#ifndef DRAW_H
#define DRAW_H

int draw_square(int x, int y, int w)
{
    int left = x;
    int right = left + w;
    int top = y;
    int bottom = y - w;
    glBegin(GL_QUADS);
	glTexCoord2i(0, 1);
	glVertex2i(left, top);
	glTexCoord2i(1, 1);
	glVertex2i(right, top);
	glTexCoord2i(1, 0);
	glVertex2i(right, bottom);
	glTexCoord2i(0, 0);
	glVertex2i(left, bottom);
	glEnd();
	return 1;
}

const int Draw_Active = 1;
const int Draw_Passive = 2;

int draw_cubes(int mode)
{
    int i;
    Cube_P cube;
    for(i = 0; i < CC; ++i) {
        cube = &cubes[i];
        if(!cube->enabled)
            continue;
        if(mode == Draw_Active) 
        {
            if(cube->state != State_Moving)
                continue;
        }
        if(mode == Draw_Passive)
        {
            if(cube->state == State_Moving)
                continue;
        }
        if(cube->state == State_Waiting) {
            glBindTexture(GL_TEXTURE_2D, 
                wait_texture);
        } else if (cube->state == State_Target) {
            glBindTexture(GL_TEXTURE_2D, 
                target_texture);
        } else {
            glBindTexture(GL_TEXTURE_2D, 
                cube_texts[cube->level-1]);
        }
        glTranslatef(cube->x, cube->y, 0);
        //glTranslatef(100, 100, 0);
        glRotatef(-cube->angle, 0, 0, 1);
        //glRotatef(10, 0, 0, 1);
	    draw_square(-CS/2, CS/2, CS);
	    //draw_square(-4, 4, 8);
	    glLoadIdentity();
	    //break;
    }
    return 1;
}


#endif
